package org.example.partner.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.example.partner.domain.Partner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.partner.domain.TenementInfo;
import org.example.partner.service.ITenementInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租户信息Controller
 *
 * @author ruoyi
 * @date 2024-06-11
 */
@Controller
@RequestMapping("/partner/tenementInfo")
public class TenementInfoController extends BaseController
{
    private String prefix = "partner/tenementInfo";

    @Autowired
    private ITenementInfoService tenementInfoService;

    @GetMapping()
    public String tenementInfo(String type,ModelMap mmp)
    {
        mmp.put("type",type);
        return prefix + "/tenementInfo";
    }

    /**
     * 查询租户信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TenementInfo tenementInfo)
    {
        startPage();
        List<TenementInfo> list = tenementInfoService.selectTenementInfoList(tenementInfo);
        return getDataTable(list);
    }

    @PostMapping("/choosePartnerList")
    @ResponseBody
    public TableDataInfo choosePartnerList(TenementInfo tenementInfo)
    {
        startPage();
        List<TenementInfo> list = tenementInfoService.choosePartnerList(tenementInfo);
        return getDataTable(list);
    }


    /**
     * 导出租户信息列表
     */
    @RequiresPermissions("partner:tenementInfo:export")
    @Log(title = "租户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TenementInfo tenementInfo)
    {
        List<TenementInfo> list = tenementInfoService.selectTenementInfoList(tenementInfo);
        ExcelUtil<TenementInfo> util = new ExcelUtil<TenementInfo>(TenementInfo.class);
        return util.exportExcel(list, "租户信息数据");
    }

    /**
     * 新增租户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存租户信息
     */
    @Log(title = "租户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TenementInfo tenementInfo)
    {
        return toAjax(tenementInfoService.insertTenementInfo(tenementInfo));
    }

    /**
     * 修改租户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TenementInfo tenementInfo = tenementInfoService.selectTenementInfoById(id);
        mmap.put("tenementInfo", tenementInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存租户信息
     */
    @Log(title = "租户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TenementInfo tenementInfo)
    {
        return toAjax(tenementInfoService.updateTenementInfo(tenementInfo));
    }

    /**
     * 删除租户信息
     */
    @Log(title = "租户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tenementInfoService.deleteTenementInfoByIds(ids));
    }
}
